package com.kgis.map.layer {
    import com.kgis.map.events.EditEvent;
    import com.kgis.map.feature.Feature;
    import com.kgis.map.handler.feature.draw.AnchorPoint;
    import flash.events.Event;
    import com.kgis.map.layer.Layer;

    public class GraphicLayer extends Layer {
        public function GraphicLayer(id:int, name:String) {
            super(id, name);
            // 平滑移动
            //this.cacheAsBitmap=true;
            // 缩放效果
            this.tweenOnZoom = false;
            this.addEventListener(Event.ADDED_TO_STAGE, addToStage);
        }

        private function addToStage(event:*):void {
            if (this.map) {
                this.map.addEventListener(EditEvent.FEATURE_DELETED, featureDeleteHandler);
            }
        }

        private function featureDeleteHandler(event:EditEvent):void {
            var feature:Feature = event.editFeature;
            var j:Number = this.numChildren - 1;
            for (j; j > -1; j--) {
                if (this.getChildAt(j) is AnchorPoint) {
                    if ((this.getChildAt(j) as AnchorPoint).parentFeature == feature) {
                        this.removeChildAt(j);
                    }

                }
            }
        }

        /**
         * 清除锚点
         */
        public function removeAnchor():void {
            var j:Number = this.numChildren - 1;
            for (j; j > -1; j--) {
                if (this.getChildAt(j) is AnchorPoint) {
                    this.removeChildAt(j);
                }
            }
        }

        override public function clone():Layer {
            var graphiclayer:GraphicLayer = new GraphicLayer(this.id, this.name);
            return graphiclayer;
        }
    }
}